package com.chenfwind.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.chenfwind.common.Constant;
import com.chenfwind.common.ResultVO;
import com.chenfwind.common.StringUtils;
import com.chenfwind.domain.Comment;
import com.chenfwind.domain.vo.CommentVO;

@Controller
@RequestMapping("/apply")
public class ApplyController {
	
	
//	@ResponseBody
//	@RequestMapping(value = "/getMessageByUser" , method = RequestMethod.POST)
//	public ResultVO<List<CommentVO>> getMessageByUser(HttpSession session,@RequestParam(value = "userId" ,required = false) String userId){
//		ResultVO<List<CommentVO>> vo = ResultVO.create();
//		if (userId == null) {
//			return ResultVO.create(Constant.CODE_NOPARAM, Constant.CODE_MSG_NOPARAM);
//		}
//		List<Comment> comment = commentService.findCommentByUserID(userId);
//		List<CommentVO> commentVO = new ArrayList<CommentVO>();
//		for (Comment com : comment) {
//			commentVO.add(Comment2CommentVO(com,null));
//		}
//		vo.setResult(commentVO);
//		vo.reCalcStatus();
//		return vo;
//	}
//	
//	public CommentVO Comment2CommentVO(Comment comment ,CommentVO commentVO){
//		if (commentVO == null) {
//			commentVO = new CommentVO();
//			commentVO.setBookName(bookService.getBookNameById(comment.getBookId()));
//			commentVO.setUserName(userService.getAccountByUID(comment.getUserId()));
//		}
//		com.chenfwind.utils.BeanUtils.copyProperties(comment, commentVO);
//		return commentVO;
//	}
//	
//	@ResponseBody
//	@RequestMapping(value = "/changeCommentStatus", method = RequestMethod.POST)
//	public ResultVO<String> changeCommentStatus(HttpSession session,@RequestParam(value = "commentId", required = false) String commentId,@RequestParam(value = "status", required = false) String status){
//		ResultVO<String> vo = ResultVO.create();
//		if (commentId == null) {
//			return ResultVO.create(Constant.CODE_NOPARAM, Constant.CODE_MSG_NOPARAM);
//		}
//		commentService.changeCommentStatusByCommentId(commentId , status);
//
//		vo.reCalcStatus();
//		return vo;
//	}
//	
//	@ResponseBody
//	@RequestMapping(value = "/submitApply", method = RequestMethod.POST)
//	public ResultVO<String> submitApply(HttpSession session,
//			@RequestParam(value = "commentInfoJson", required = false) String commentInfoJson){
//			ResultVO<String> vo = ResultVO.create();
//			CommentVO commentInfo = JSON.parseObject(commentInfoJson, CommentVO.class);
//			if (commentInfo == null) {
//				return ResultVO.create(Constant.CODE_NOPARAM, Constant.CODE_MSG_NOPARAM);
//			}
//			Comment comment = CommentVO2Comment(commentInfo , null);
//
//			comment.setCreateTime(new Date());
//			commentService.save(comment);
//			vo.reCalcStatus();
//			return vo;
//	}
//	
//	public Comment CommentVO2Comment(CommentVO commentVO , Comment comment ){
//		if (comment == null) {
//			comment = new Comment();
//			comment.setId(StringUtils.genUUID());
//		}
//		com.chenfwind.utils.BeanUtils.copyProperties(commentVO, comment);
//		return comment;
//	}
}
